use std::sync::Arc;
use lazy_static::lazy_static;
use rusqlite::Error;
use tokio::sync::Mutex;
use crate::lbean::user::UserTabBean;
use crate::ldb::{get_db, user_db};


/* 用户添加 */
pub(crate) async fn user_add(bean: UserTabBean) -> rusqlite::Result<()> {
    let db = get_db();
    let db = db.lock().await;
    let user_list = user_db::user_select_by_phone(&db.conn, &bean.phone)?;
    if !user_list.is_empty() {
        return Err(Error::InvalidColumnName("手机号已经存在".to_string()));
    }

    user_db::user_add(Some(&db.conn), None, bean)?;

    Ok(())
}

/* 找到全部用户 */
pub(crate) async fn user_find_all() -> rusqlite::Result<Vec<UserTabBean>> {
    let db = get_db();
    let db = db.lock().await;
    user_db::user_select_all(&db.conn)
}

/* 根据手机号查询 */
pub(crate) async fn user_find_by_phone(phone:&String) -> rusqlite::Result<Vec<UserTabBean>> {
    let db = get_db();
    let db = db.lock().await;
    user_db::user_select_by_phone(&db.conn, phone)
}






























